package 码云作业;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class text02 {
	 public static boolean buffRead(String year){
	        boolean flag = false;
	        FileReader fr=null;
	        BufferedReader br =null;
	        try {
	            fr=new FileReader("doc/worldcup.txt");
	            br=new BufferedReader(fr);
	            String str =br.readLine();
	            while(str!=null){
	                if(str.substring(0,4).equals(year)){
	                    System.out.println(year+"年世界杯冠军为："+str.substring(5));
	                    flag=true;
	                    break;
	                }else{
	                    str=br.readLine();
	                }
	            }
	        }catch (IOException e){
	            e.printStackTrace();
	        }finally {
	            try {
	                if (fr!=null){
	                    fr.close();
	                }
	                if (br !=null){
	                    br.close();
	                }
	            }catch (IOException e){
	                e.printStackTrace();
	            }
	        }
	        return flag;
	    }

	    public static void main(String[] args) {
	        Scanner input = new Scanner(System.in);
	        System.out.print("请输入年份：");
	        String year = input.next();
	        if (!buffRead(year)){
	            System.out.println(year+"年没有举办世界杯。");
	        }
	    }
}
